package com.jmz.apt.api.Provider;

import com.jmz.apt.api.Utils.MD5Util;
import com.jmz.apt.api.entity.dbEntity.JmzAdminUser;
import com.jmz.apt.api.entity.dbEntity.TimeTygpGroup;
import com.jmz.apt.api.entity.dbEntity.TimeTygpGroupItems;
import com.jmz.apt.api.message.request.Condition;
import com.jmz.apt.api.message.request.Query;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class TimeTygpGroupItemsProvider extends BaseProvider {

    public String getCount(List<Condition> conditions) {
        return super.count(conditions);
    }

    public String select(String columns, List<Condition> conditions, Query query) {
        return  super.findAll(columns,conditions,query);
    }

    public String getTableName(){
        return "time_tygp_group_items";
    }

    public String insert(TimeTygpGroupItems timeTygpGroupItems) {
        SQL sql = new SQL();
        sql.INSERT_INTO(getTableName());
        if (timeTygpGroupItems.getTygpGroupId() != null) {
            sql.VALUES("tygp_group_id", "#{tygpGroupId}");
        }
        if (timeTygpGroupItems.getTygpId() != null) {
            sql.VALUES("tygp_id", "#{tygpId}");
        }
        return sql.toString();
    }

    public String selectOne(TimeTygpGroupItems timeTygpGroupItems) {
        SQL sql = new SQL();
        sql.SELECT("*");
        sql.FROM(getTableName());
        if (timeTygpGroupItems.getTygpGroupId() != null) {
            sql.WHERE("tygp_group_id=#{tygpGroupId}");
        }
        if (timeTygpGroupItems.getTygpId() != null) {
            sql.WHERE("tygp_id=#{tygpId}");
        }
        String lastSql = sql.toString();
        return lastSql + "limit 1";
    }

    public String delete(TimeTygpGroupItems timeTygpGroupItems) {
        return new SQL() {{
            DELETE_FROM(getTableName());
            WHERE("tygp_id=#{tygpId}"); //暂时禁止批量删除
            WHERE("tygp_group_id = #{tygpGroupId}"); //暂时禁止批量删除
        }}.toString();
    }

    public String batchDelete(TimeTygpGroupItems timeTygpGroupItems) {
        return new SQL() {{
            DELETE_FROM(getTableName());
            WHERE("tygp_group_id = #{tygpGroupId}"); //暂时禁止批量删除
        }}.toString();
    }

    public String update(TimeTygpGroupItems timeTygpGroupItems) {
        return new SQL() {{
            UPDATE(getTableName());
            if (timeTygpGroupItems.getTygpId() != null) {
                SET("tygp_id = #{tygpId}");
            }
            if (timeTygpGroupItems.getTygpGroupId() != null) {
                SET("tygp_group_id = #{tygpGroupId}");
            }
            WHERE("id = #{id}");
        }}.toString();
    }
}
